//
//  MyTabBar.m
//  杂志看天下
//
//  Created by 秦建英 on 14-2-17.
//  Copyright (c) 2014年 秦建英. All rights reserved.
//

#import "MyTabBar.h"

@implementation MyTabBar

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}



- (void)createTabBarWithBackgroundImageName:(NSString *)bgImageName andButtonsImageName:(NSArray *)buttonsImageName andButtonsSelectImageName:(NSArray *)buttonsSelectImageName andButtonsTitle:(NSArray *)buttonsTitle andSEL:(SEL)sel andClass:(id)classObject
{
    // 创建背景
    [self createBackGroundImageWithImageName:bgImageName];
    // 创建item
    for(int i=0;i<buttonsImageName.count;i++)
    {
        [self createItemWithButtonImageName:[buttonsImageName objectAtIndex:i] andButtonSelectImageName:[buttonsSelectImageName objectAtIndex:i] andTitle:[buttonsTitle objectAtIndex:i] andSEL:sel andClass:classObject andIndex:i];
    }
}

- (void)createBackGroundImageWithImageName:(NSString *)imageName
{
    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:imageName]];
    imageView.frame = self.bounds;
    [self addSubview:imageView];
}

- (void)createItemWithButtonImageName:(NSString *)buttonImageName andButtonSelectImageName:(NSString *)buttonSelectImageName andTitle:(NSString *)title andSEL:(SEL)sel andClass:(id)classObject andIndex:(int)index
{
    UIView *groundView = [[UIView alloc] init];
    groundView.frame = CGRectMake(0+self.bounds.size.width/4*index, 0, self.bounds.size.width/4, self.bounds.size.height);
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake((64-45)/2, 3, 65, 40);
    [btn setImage:[UIImage imageNamed:buttonImageName] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:buttonSelectImageName] forState:UIControlStateSelected];
    [btn addTarget:classObject action:sel forControlEvents:UIControlEventTouchUpInside];
    btn.tag = index;
    [groundView addSubview:btn];
    
    UILabel *label = [[UILabel alloc] init];
    label.frame = CGRectMake((64-45)/2, 35, 65, 8);
    label.text = title;
    label.textColor = [UIColor colorWithRed:0.30f green:0.30f blue:0.30f alpha:1.00f];
    label.font = [UIFont systemFontOfSize:8];
    label.textAlignment = NSTextAlignmentCenter;
    label.backgroundColor = [UIColor clearColor];
    [groundView addSubview:label];
    
    [self addSubview:groundView];
}



/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
